﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统账户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css" media="all">
    <style>
        .layui-form-select input{width: 100%;!important;}
        .layui-form-label{width: 100px;text-align: justify;height: 20px;}
        .layui-form-label:after{content:'';width: 100%;display: inline-block;}
        .layui-input-block{margin-left: 140px;}
        #date1,#date2{margin-bottom: 10px;}
        ._submit{width: 100%;text-align: center;}
        .layui-select-title{margin-left: 10px;}
        .bixuan{left: 4px;}
        .layui-form-select{width: 165px;}
        .layui-form-select input{width: 190px;}
        .layui-form-select .layui-input{padding-right: 0;}
        /*
        设置样式居中
        */
        /*.layui-form-item{padding-left:76px;}*/
        .formTop_inTs{width: 80%;}
        .chaxun{width: 100%;}
        .layui-select-title{margin-left: 0;}
        .masksx .forms{padding-left: 90px;}

        .layui-input-block{margin-bottom: 8px;}
        .title{position: relative;z-index: 99;}
        .layui-form-select dl{height: 200px;}
        .butns{float: left;width: 20%;}
        .formTop .formTop_inT{width: 40%;}
    </style>
</head>
<body>
<form class="layui-form layui-form-pane" id="form_7grid" action="" >

    <div class="formTop" stylr="font-size:12px;">
        <div class="layui-inline formTop_inT" style="float: left;">
            <div class="layui-input-inline formTop_inTs">
                <input type="text" name="username" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input chaxun" style="width: 100%">
            </div>
        </div>
        <div class="butns">
            <button class="layui-btn" type="button"  onclick="queryUser()">查询</button>
            <button class="layui-btn layui-btn-normal quanxian" type="button" style="background-color: #ff8f3b;" onclick="enterpriseAdd()" QX="api/user/regist.do">添加</button>
        </div>
    </div>
    <table id="demo" lay-filter="test"></table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs quanxian" lay-event="edit" QX="api/user/editUser.do">编辑</a>
    </script>

</form>
<a class="dayin" type="button" id="dlink" onclick="" style="float: right; position: fixed; right: 50px; bottom: 50px; z-index: 999;"></a>

<div class="mask">
        <div class="masksx">
            <div class="title"><span class="titleL">添加用户</span><span class="close">×</span></div>
            <div class="forms">
            <form class="layui-form addUser" method="post" action="">

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>操作员名称<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="empname1" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input" value="">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>密码<span class="maohao">：</span></label>
                    <div class="layui-input-block" style="position: relative;">
                        <input type="password" name="pwd"  placeholder="请输入" lay-verify="pass|required" autocomplete="off" class="layui-input">
                        <i class="layui-icon qiehuan"
                           style="position: absolute;right: 94px;top: 10px;width: 20px; height: 20px;text-align: center;">&#xe705;
                        </i>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>用户组<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <select lay-verify="required" lay-search="" name="groupcode">
                            <option value=""></option>
                        </select>
                        <input type="text" name="securid_G" placeholder="" autocomplete="off" class="layui-input yinchang">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>员工类型<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <select lay-verify="required" lay-search="" name="emptype" lay-filter="yuangongleixing" class="empjs">
                            <!--<option value=""></option>
                            <option value="1">1</option>
                            <option value="2">2</option>-->
                        </select>
                        <input type="text" name="securid_Em" placeholder="" autocomplete="off" class="layui-input yinchang">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>企业类型<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <!--<select name="comptype" lay-search="">-->
                        <select lay-verify="required" lay-search="" name="comptype" lay-filter="qiyeleixing" class="compjs">
                            <!--<option value=""></option>-->
                            <!--<option value="2">2</option>-->

                        </select>
                        <input type="text" name="securid_Com" placeholder="" autocomplete="off" class="layui-input yinchang">
                    </div>

                </div>
                <div class="layui-form-item" lay-filter="suoshuqiye">
                    <label class="layui-form-label"><span class="bixuan">*</span>所属企业<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <div class="layui-form" lay-filter="test2">
                            <select lay-verify="required" name="compid.compid" lay-search="" class="compid"  >
                                <!--<option value=""></option>
                                <option value="2">2</option>-->

                            </select>
                            <input type="text" name="securid_Compid" placeholder="" autocomplete="off" class="layui-input yinchang securid_Compid">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>身份证号<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="securid" lay-verify="identity|required" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出生日期<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="date1" lay-verify="required" placeholder="yyyy-MM-dd" name="birthday">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">电子邮箱<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="email" lay-verify="email" autocomplete="off" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="bixuan">*</span>电话号码<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="tel" name="motel" lay-verify="required|yidongguhua"  placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系人<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="contack" lay-verify="required" autocomplete="off"  placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮政编码<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="number" name="postidaddr" lay-verify="code" autocomplete="off"  placeholder="请输入" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">通讯地址<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="addr" lay-verify="required" autocomplete="off"  placeholder="请输入" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">户籍地址<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="addr2" lay-verify="required" autocomplete="off"  placeholder="请输入" class="layui-input" value=""/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">到职日期<span class="maohao">：</span></label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="test-limit1" lay-verify="required" placeholder="yyyy-MM-dd" name="rdate">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">启用状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="0" title="启用" checked="" lay-filter="danxuans">
                        <input type="radio" name="sex" value="1" title="禁用" lay-filter="danxuans">

                </div>


                    <input type="hidden" class="layui-input" name="opid" value="" />
                    <!--<input type="hidden" class="layui-input" name="useing" value="0" />-->
                    <input type="hidden" class="layui-input" name="state" value="0" />




                <div class="_submit">
                    <button class="layui-btn layui-btn-sm tijiao" lay-submit lay-filter="_subm">提交</button>
                    <!--<button class="layui-btn layui-btn-sm " type="reset">重置</button>-->
                </div>

            </form>

            </div>
        </div>

</div>

<div class="jieshou"></div>

<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>
<script>
	//2017.12.13

    function queryUser() {                          //查询
        var _inputVal=$('.chaxun').val();        //获取输入框信息
        _inputVal=$.trim(_inputVal);             //搜索框值去前后空格

        //判断输入框是否包含关键字及特殊符号
        console.log(!AntiSqlValid(_inputVal))
        if ( !AntiSqlValid(_inputVal) ){
            if(lbq('api/user/loadUserList.do')) {
                API.accountAdmin({
                    'empname': _inputVal,
                    'p': getCookie('yanzheng')
                });
            }
        }else {
            layer.msg('请勿输入特殊符号');
            $('.chaxun').val('');
        };
    };
    //用户添加
    function enterpriseAdd() {
        $('input').each(function () {                       //匹配所有input框  属性为必填的项添加*标识符
            if($(this).attr('lay-verify')=="required"){
                $(this).parent().prev().prepend('<span class="bixuan">*</span>')
            }
        });
        sessionStorage.ajaxpan='tianjia';
        $('.mask').show();                          //弹框出现
        $('.mask input').val('');//清空弹框input内容
        $('.mask select').val('');
        $('#mark').val(1)                           //隐藏域赋值
        $('.titleL').html('添加用户')

    layui.use(['form', 'layedit', 'laydate','table','element'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,element=layui.element;


            form.on('select(qiyeleixing)', function(data){  
				  leixing=$('[name="comptype"]').val();
				 jie='';
				  console.log(leixing)
				  console.log(data.value )
				  var _indeX=data.value
                $.each(xiala, function (k ,v) {
//                    console.log(v[0].compType == _indeX)
                    if(v[0] && v[0].compType == _indeX){
                        jie = v;
                    }
                });

				  console.log(jie)
				  $('[name="compid.compid"]').html('');
	         	for(var i=0;i<jie.length;i++){
	         		$('[name="compid.compid"]').append('<option class="opt" value="'+jie[i].compid+'">'+jie[i].compName+'</option>')
	         	}
//			  
			   form.render();
			});
            

	})

        alertoff();
        

    }

    layui.use(['form', 'layedit', 'laydate','table','element'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,table=layui.table
            ,element=layui.element;
        jiazais();
        var enabled=0;
        form.on('radio(danxuans)', function(data){
            console.log(data.elem); //得到radio原始DOM对象
            console.log(data.value); //被点击的radio的value值
            enabled=data.value;
        });


        $('.addUser').attr('action',urls+'/api/user/regist.html');//动态加载form 表单提交地址

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var arrs=[];
        var arrs2=[];
        dayintishi('.dayin');

        if(lbq('api/user/loadUserList.do')) {
            API.accountAdmin({'p': getCookie('yanzheng')}, function () {
                console.log(arguments, '坏笑');		//arguments对象是比较特别的一个对象，实际上是当前函数的一个内置属性。arguments非常类似Array，但实际上又不是一个Array实例
                xiala = arguments[0];
                console.log(xiala)
                arrs2=xiala.compDropDown;
                $("[name='emptype']").html('')
                for (var i = 0; i < xiala.userType.length; i++) {
                    $("[name='emptype']").append('<option value="' + xiala.userType[i].p_value + '">' + xiala.userType[i].p_name + '</option>');
                }
                $("[name='comptype']").html('')
                for (var i = 0; i < xiala.compDropDown.length; i++) {
                    $("[name='comptype']").append('<option value="' + xiala.compDropDown[i].p_value + '">' + xiala.compDropDown[i].p_name + '</option>')
                }
                ajaxs('/api/permi/loadPermi.do','post',{},function (data) {
                    var datas=data.data;
                    console.log(datas,'<><><><><>')
                    arrs=datas;
                    for(var i=0;i<datas.length;i++){
                        $('[name="groupcode"]').append('<option value="'+datas[i].id+'">'+datas[i].groupname+'</option>')
                    }
                    $('[data-field="addrs"]').each(function (k,v) {
                        for(var i=0;i<arrs.length;i++){
                            if($(v).children('div').text()==arrs[i].id){
                                $(v).children('div').text(arrs[i].groupname);
                            };
                        };
                    });
                    form.render();

                });


            });      //调用页面数据查询 渲染
        }
	
	
        $('.close').click(function () {     //遮罩层隐藏
            $('.mask').hide();
        })

        //日期
        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });
        //自定义验证规则
        form.verify({
            pass: [ /^[A-Za-z0-9]{6,20}$/, '密码必须6到12位']         //密码验证
            ,code: [ /^[0-9]{6}$/, '请输入正确的邮政编码']         //邮政验证
//            ,yidongguhua:[/^[\d]{4}-[\d]{7}$/, '请输入正确的联系方式']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //控制密码查看功能
        $('.qiehuan').click(function () {
            $(this).prev().attr('type')=='type'?$(this).prev().attr('type','password'):$(this).prev().attr('type','type');
        })

        panduanshijiantow('#test-limit1','#test-limit2',1000,1000,'.layui-btn-primary');  //入职时间和离职时间判断
        //监听工具条
        table.on('tool(test)', function(obj){ //注<span class="maohao">：</span>tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'detail'){ //查看
                //do somehing
                console.log(obj)
                var datas=obj.data;
                var qiyeleixings;
                switch (datas.emptype){
                    case 1:
                        datas.emptype='企业人员';
                        break;
                    case 2:
                        datas.emptype='施工队';
                        break;
                    case 3:
                        datas.emptype='供货商';
                        break;
                    case 4:
                        datas.emptype='系统管理员';
                        break;
                }
                for(var i=0;i<arrs.length;i++){
                    if(arrs[i].id==datas.groupcode){
                        datas.groupcode=arrs[i].groupname
                    }
                };
                for(var i=0;i<arrs2.length;i++){
                    if(arrs2[i].id==datas.compid.comptype){
                        qiyeleixings=arrs2[i].p_name;
                    }
                };
                $('.bixuan').hide();

                $("[name='opid']").val(datas.opid);
                $("[name='namespan']").val(datas.empname);
                $("[name='empname1']").val(datas.empname);
                $("[name='pwd']").val(datas.pwd);
                $("[name='securid_G']").val(datas.groupcode);
                $("[name='emptype']").val(datas.emptype);
                $("[name='securid']").val(datas.securid);
                $("[name='birthday']").val(times(datas.birthday));
                $("[name='email']").val(datas.email);
                $("[name='motel']").val(datas.motel);
                $("[name='contack']").val(datas.contack);
                $("[name='postidaddr']").val(datas.postidaddr);
                $("[name='addr']").val(datas.addr);
                $("[name='addr2']").val(datas.addr2);
                $("[name='rdate']").val(times(datas.rdate));
                $("[name='ldate']").val(times(datas.ldate));
                $("[name='securid_Com']").val(qiyeleixings);
                $("[name='securid_Compid']").val(datas.compid.compname);
                $("[name='securid_Em']").val(datas.emptype);
				$('[name="sex"]').each(function (k,v) {
                    if($(v).val()==datas.useing){
                        $(v).prop( "checked", true );

                    }
                })
                form.render();

                $('.mask').show();                           //弹框隐藏
                $('.mask .titleL').html('查看用户');         //改变标题
                $('.mask input').attr('disabled','true');   //查看时 禁止所有input框输入
                $('.yinchang').each(function () {
                    $(this).show().prev().hide();
                });

                $('._submit').hide();
                $('.main_onR').each(function () {
                    console.log($(this).html()==null||$(this).html()=='')
                    if($(this).html()==null||$(this).html()==''){
                        $(this).html('无')
                    }
                })
            } else if(layEvent === 'edit'){ //编辑
                //do something
     			console.log(xiala);
     			console.log(obj)
     			var datas=obj.data;
     			var jie;
     			var leixing;
     			
     			var zhi=obj.data.compid.compid;

         	    var _indeX=obj.data.compid.comptype;

                $.each(xiala, function (k ,v) {
                    console.log(v[0] && v[0].compType == _indeX)
                    if(v[0] && v[0].compType == _indeX){
                        jie = v;
                    }
                });

				  console.log(jie)
				  $('[name="compid.compid"]').html('');
	         	for(var i=0;i<jie.length;i++){
	         		$('[name="compid.compid"]').append('<option class="opt" value="'+jie[i].compid+'">'+jie[i].compName+'</option>')
	         	}

	       		$('[name="compid.compid"]').val(zhi);
			    form.render();
                form.on('select(qiyeleixing)', function(data){
         		console.log(obj)
         		console.log(xiala)
                var jie='';
                console.log(data.value )
                var _indeX=data.value;
                $.each(xiala, function (k ,v) {
//                    console.log(v[0].compType == _indeX)
                    if(v[0] && v[0].compType == _indeX){
                        jie = v;
                    }
                });
//				  console.log(jie,'我是下拉')
				  $('[name="compid.compid"]').html('');
	         	for(var i=0;i<jie.length;i++){
	         		$('[name="compid.compid"]').append('<option class="opt" value="'+jie[i].compid+'">'+jie[i].compName+'</option>')
	         	}
	       		$('[name="compid.compid"]').val(zhi);
			   form.render();
			});
                $('.bixuan').show();
              
              	$("[name='opid']").val(datas.opid);
                $("[name='namespan']").val(datas.empname);
                $("[name='empname1']").val(datas.empname);
                $("[name='pwd']").val(datas.pwd);
                
                $("[name='emptype']").val(obj.data.emptype);
                $("[name='securid']").val(datas.securid);
                $("[name='birthday']").val(times(datas.birthday));
                $("[name='email']").val(datas.email);
                $("[name='motel']").val(datas.motel);
                
                $("[name='contack']").val(datas.contack);
                $("[name='postidaddr']").val(datas.postidaddr);
                $("[name='addr']").val(datas.addr);
                $("[name='addr2']").val(datas.addr2);
                $("[name='rdate']").val(times(datas.rdate));
                $("[name='ldate']").val(times(datas.ldate));
                $("[name='groupcode']").val(datas.groupcode);
                $("[name='compid.compid']").val(datas.compid.compid);
                $(".compjs").val(datas.compid.comptype);
                $('[name="sex"]').each(function (k,v) {
                    if($(v).val()==datas.useing){
                        $(v).prop( "checked", true );
                    }
                });
                $('.mask input').attr('disabled',false);   //查看时 禁止所有input框输入

                form.render();
                
                console.log(datas.compid.compid, '<----------------|||||')
              
                sessionStorage.ajaxpan='bianji'
                $('.titleL').html('编辑用户');
                $('.addUser').attr('action',urls+'/api/user/editUser.html');
                alertoff();

          			
          			
          			$('.mask').show();
                    $('#mark').val(1);                          //隐藏域赋值

       

            }
        });
     
        
          
        //添加监听   检查企业名称是否存在
        var time = 0;
        var chushi;
  $("[name='empname1']").focus(function(){
  	$("[name='empname1']").keyup(function () {
            clearTimeout(time);
            console.log(chushi)
            var root = this;
            // 小华更改,128 编辑企业--提交按钮被禁用
            time = setTimeout(function () {
                var _names=$(root).val();               //获取页面值
                _names=$.trim(_names);
                console.log(_names==chushi,'>>>>>>>>>>>>>>>>>>>')
                if(_names){
                    if(_names==chushi){
                        return;
                    }
                    ajaxs('/api/public/cheName.do','get',{"type":2,"name":_names},function (data) {
                        console.log(data)
                        if(data.data=='0'){
//                            layer.msg('企业名可用');
                            $('.tijiao').removeAttr('disabled').removeClass('layui-btn-disabled');
                        }else{
                            layer.msg('用户名称已存在 请重新输入');
                            $('.tijiao').attr('disabled',"true").addClass('layui-btn-disabled');
                        }
                    })
                }
            }, 500)

        })
  })
            
        //监听提交
        form.on('submit(_subm)', function(data){

            console.log(data.field,'<-----------------') //当前容器的全部表单字段，名值对形式<span class="maohao">：</span>{name: value}
            var now = new Date();                               //获取当前时间
            now.setFullYear(now.getFullYear()+1);               //设置时间
            var time1 = now.format("yyyy-MM-dd hh:mm:ss");      //时间转换
            console.log(time1)
            $("[name='accendtime']").val(time1);                  //赋值
            data.field.state=0;
            data.field.p=getCookie('yanzheng');
            data.field.ldate=time1;
            data.field.useing=enabled;

            if(sessionStorage.ajaxpan=='tianjia'){
                formAlertAjax('/api/user/regist.do',data.field,'.tijiao'); //弹框式页面信息修改调用
            }else if(sessionStorage.ajaxpan=='bianji'){
                formAlertAjax('/api/user/editUser.do',data.field,'.tijiao'); //弹框式页面信息修改调用
            }

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    })

</script>
</body>
</html>